<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        const mySqrt = (x) => {
            let l = 1, r = x, mid;
            while (l <= r - 0.000001) {
                mid = l + (r - l) / 2
                if (mid * mid === x) {
                    return mid
                }
                if (mid * mid < x) {
                    l = mid
                } else {
                    r = mid
                }
            }
            return mid
        }
        console.log(mySqrt(8));
    </script>
</body>

</html>